#ifndef FMMT
#define FMMT

#include <math.h> 
#include "miscfunc.h"
#include "messages.h"

class fmmt
{
private:
	double dat[360], aux[360];	// armazena o seno e cosseno de 0 a 360 graus
	float pi;					// numero PI

public:
	double ampl;					// amplitude da onda
	int phase;					// fase em graus (inteiro)
	void init(void);			// inicializa os vetores dat e aux
	void setampl(double value);	// seta a amplitude
	void setphase(double value);	// seta a fase
	void drawfmmtcir(double lbase);	// desenha em opengl o diagrama circular
	void drawfmmtplan(double posx, double posy, double maxx, double maxy);
	~fmmt(void);
};

void fmmt::init(void)
{
	int i;

	pi=4*atan(1);

	for(i=0; i<360; i++)
	{
		dat[i]=sin(d2r(i));
		aux[i]=cos(d2r(i));
	}
	ampl=1;
	phase=0;
}

void fmmt::setampl(double value)
{
	ampl=value;
}

void fmmt::setphase(double value)
{
	if (value<0) value=360+value;
	phase=(int)value;
}
/*
void fmmt::drawfmmtcir(double lbase)
{
	double temp,x,y;
	double x0,y0;
	int i,j;
	
	j=phase;

	glLineWidth(2);
	glBegin(GL_LINE_STRIP);
	for(i=0;i<360;i+=5)
	{
		if(i+j>=360) j=-i;
		temp=lbase+ampl*aux[i];
		x=temp*aux[i+j];
		y=temp*dat[i+j];
		glVertex2f(x,y);
		if(i==0) {x0=x;y0=y;}
	}
	glVertex2f(x0,y0);
	glEnd();

	glLineWidth(1);
	glEnable(GL_LINE_STIPPLE);
	glLineStipple(3,43690);
	glBegin(GL_LINES);
	glVertex2f(0,0);
	glVertex2f(250*aux[phase],250*dat[phase]);
	glEnd();
	glLineStipple(1,65535);
	glDisable(GL_LINE_STIPPLE);
}
*/
fmmt::~fmmt(void)
{
	printf(MSG61);
}
/*
void fmmt::drawfmmtplan(double posx, double posy, double multx, double multy)
{
	double x,y;
	int i,j;
	
	if(phase<0) j=360+phase;
	else j=phase;
	j+=90;
	if(j>=360) j-=360;

	glLineWidth(2);
	glBegin(GL_LINE_STRIP);
	for(i=0;i<360;i+=2)
	{
		if(i+j>=360) j=-i;
		x=i*multx;
		y=ampl*dat[i+j]*multy;
		glVertex2f((x+posx),y+posy);
	}
	glEnd();

	
	glLineWidth(1);
	glEnable(GL_LINE_STIPPLE);
	glLineStipple(3,43690);
	glBegin(GL_LINES);
	j=90-j;
	if(j>360) j=j-360;
	glVertex2f(posx+j*multx,0);
	glVertex2f(posx+j*multx,100);
	glEnd();
	glLineStipple(1,65535);
	glDisable(GL_LINE_STIPPLE);
}

*/
void calcres(fmmt *a, fmmt *b, double *mag, int *phas)
{
	complex fas_a;
	complex fas_b;
	complex fas_c;

	fas_a.pold((double)a->ampl,(double)a->phase);
	fas_b.pold((double)b->ampl,(double)b->phase);
	fas_c=fas_a+fas_b;
	
	*mag=fas_c.abs();
	*phas=(int)fas_c.phas(DEG);
}
#endif
